﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class GUI_MasterPages_BabysittersRegistration3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void sittersform2_Click(object sender, EventArgs e)
    {
        int bsID = Convert.ToInt32(Request.QueryString["bsID"]);
        int acctID = Convert.ToInt32(Request.QueryString["bAcctID"]);
        //int bsID = 8;
        //int acctID = 25;

        string connStr = ConfigurationManager.ConnectionStrings["CSConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);

        SqlCommand cmd1 = new SqlCommand("BSHealth", conn);
        cmd1.CommandType = CommandType.StoredProcedure;

        cmd1.Parameters.Add(new SqlParameter("@allg", TextBox18.Text));
        cmd1.Parameters.Add(new SqlParameter("@pet", TextBox1.Text));
        cmd1.Parameters.Add(new SqlParameter("@bsID", bsID));

        conn.Open();
        cmd1.ExecuteNonQuery();
        conn.Close();

        SqlCommand cmd2 = new SqlCommand("BabySittersRegistration3_con", conn);
        cmd2.CommandType = CommandType.StoredProcedure;

        cmd2.Parameters.Add(new SqlParameter("@bsID", bsID));
        cmd2.Parameters.Add(new SqlParameter("@clubs", conditions1(RadioButtonList3)));
        cmd2.Parameters.Add(new SqlParameter("@cinemas", conditions1(RadioButtonList4)));
        cmd2.Parameters.Add(new SqlParameter("@otherEvents", conditions1(RadioButtonList5)));
        cmd2.Parameters.Add(new SqlParameter("@withparentsathome", conditions2(CheckBoxList1, 0)));
        cmd2.Parameters.Add(new SqlParameter("@withparentsatclub", conditions2(CheckBoxList1, 3)));
        cmd2.Parameters.Add(new SqlParameter("@withmaidathome", conditions2(CheckBoxList1, 1)));
        cmd2.Parameters.Add(new SqlParameter("@withmaidatclub", conditions2(CheckBoxList1, 4)));
        cmd2.Parameters.Add(new SqlParameter("@aloneathome", conditions2(CheckBoxList1, 2)));
        cmd2.Parameters.Add(new SqlParameter("@aloneatclub", conditions2(CheckBoxList1, 5)));

        conn.Open();
        cmd2.ExecuteNonQuery();
        conn.Close();

        helper(acctID, ec1, ec2, ec3, ec4);
        if (ec5.Text != "")
        {
            helper(acctID, ec5, ec6, ec7, ec8);
        }

        Response.Redirect("http://www.cairositters.com/GUI/Pages/BabysitterRegistration4.aspx?bsID=" + bsID + "&bAcctID=" + acctID);
        //Response.Redirect("http://localhost:60070/CSWebSite_v1.0/GUI/Pages/BabysitterRegistration4.aspx?bsID=" + bsID + "&bAcctID=" + acctID);
    }
   
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedValue == "Yes")
        {
            TextBox18.Enabled = true;
        }
        else
        {
            TextBox18.Enabled = false;
        }
    }
    protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList2.SelectedValue == "Yes")
        {
            TextBox1.Enabled = true;
        }
        else
        {
            TextBox1.Enabled = false;
        }
    }

    protected bool conditions1(RadioButtonList r)
    {
        bool b;
        if (r.SelectedValue == "Yes")
            b = true;
        else
            b = false;

        return b;
    }

    protected bool conditions2(CheckBoxList c, int i)
    {
        bool b;
        if (c.Items[i].Selected)
            b = true;
        else
            b = false;

        return b;
    }

    protected void helper(int a, TextBox t1, TextBox t2, TextBox t3, TextBox t4)
    {
        string connStr = ConfigurationManager.ConnectionStrings["CSConn"].ToString();
        SqlConnection conn = new SqlConnection(connStr);

        SqlCommand cmd3 = new SqlCommand("Registration_EmergencyContacts", conn);
        cmd3.CommandType = CommandType.StoredProcedure;

        cmd3.Parameters.Add(new SqlParameter("@ec_name", t1.Text));
        cmd3.Parameters.Add(new SqlParameter("@ec_mobile_num", t2.Text));
        cmd3.Parameters.Add(new SqlParameter("@ec_phone_num", t3.Text));

        conn.Open();
        int ecID = Convert.ToInt32((decimal)cmd3.ExecuteScalar());
        conn.Close();

        SqlCommand cmd5 = new SqlCommand("Registration_EmergencyContacts_A", conn);
        cmd5.CommandType = CommandType.StoredProcedure;

        cmd5.Parameters.Add(new SqlParameter("@acctID", a));
        cmd5.Parameters.Add(new SqlParameter("@ecID", ecID));
        cmd5.Parameters.Add(new SqlParameter("@relationship", t4.Text));

        conn.Open();
        cmd5.ExecuteNonQuery();
        conn.Close();
    }
}